package com.jeeplus.modules.guide.service;
import com.jeeplus.database.datasource.annotation.DS;
import com.jeeplus.modules.guide.mapper.WXMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;;import java.util.HashMap;
import java.util.List;


/**
 * ClassName: SWService
 * Function:  税务首页统计分析
 * Date:      2022/7/4 10:53
 *
 * @author hanKongbin
 * version    V1.0
 */
@DS("queuing")
@Service
@Slf4j
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class WXService {
    private final WXMapper wxMatter;

    public List <HashMap <String,Object>> mobileListByWX(){
        return wxMatter.mobileListByWX();
    }

    public List<String> findTable(){
        return wxMatter.findTable();
    }

    @Transactional(readOnly = false)
    public Integer inserTableTimeValue(String tableName){
        List <HashMap <String, String>> tableTimeValue = wxMatter.findTableTimeValue();
        List <HashMap <String, String>> swList = wxMatter.swTypeName();
        try {
            for(HashMap <String, String> list : tableTimeValue){
                wxMatter.inserTableTimeValue("1",list.get("area"),list.get("times"),String.valueOf(list.get("num")),tableName);
            }
            for(HashMap <String, String> list : swList){
                wxMatter.inserTableTimeValue("2",list.get("area"),"2",String.valueOf(list.get("num")),tableName);
            }
            wxMatter.updateTable(tableName);
            return 1;
        }catch (Exception e){
            e.printStackTrace();
            return 0;
        }
    }

}